home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / conjug / conjug.pro
Text File  |  1986-05-14  |  4KB  |  128 lines

  1.    /* Conjugation program
  2.     by Neil J. Rubenking
  3.  
  4.     WARNING:  I am a PROLOG novice.  This program is not to be
  5.     taken as an example of good programming practice.  In fact,
  6.     if you see any true blunders of style, I'd appreciate your
  7.     letting me know about them!
  8.  
  9.     Type in a sentence, and the program reverses the "person".
  10.     "I am the only friend you have" becomes "You are the only
  11.     friend I have".  And so on.  Enter a blank line to quit.
  12.  
  13.   */
  14. nowarnings
  15. domains
  16.     words = string*
  17. predicates
  18.     run
  19.     Do_Line
  20.     append(words, words, words)
  21.     conjugate(string)
  22.     conj(words, words)
  23.     change(words, words)
  24.     splitup(string, words)
  25.     WriteList(words)
  26. goal
  27.     run.
  28.  
  29. clauses
  30. run :-
  31.     MakeWindow(1,7,112,"Conjugate",0,0,25,80),
  32.     MakeWindow(1,7,0,"",2,2,21,76),
  33.     Write("Enter single sentences -- the 'person' will be reversed."),nl,
  34.     Do_Line.
  35.  
  36. Do_Line :-
  37.     write(":>"),
  38.     ReadLn(Line),
  39.     not(conjugate(Line)), /* Conjugate ends with a "WriteList", which    */
  40.             /* stops by FAILing.  Hence the "not".  Since  */
  41.             /* a blank line succeeds with the FIRST rule   */
  42.             /* in Conjugate, a blank line ends the program.*/
  43.     Do_Line.
  44.  
  45.  
  46. conjugate("").
  47.   /*  TO conjugate a sentence, we first split it up into a list of */
  48.   /*  words.  We append a marker to the beginning and end of the   */
  49.   /*  list, to help with capitalization.  Then we call "conj"       */
  50.   /*  to find the conjugation of that list.  Finally, we strip off */
  51.   /*  the markers and print the resulting list.               */
  52.  
  53.  
  54. conjugate(Strin) :- splitup(Strin,List),
  55.     append(["ZXQbegin"],List,List2),
  56.     append(List2,["ZXQend"],List3),
  57.     conj(List3,NewList),
  58.     append(List4,["ZXQend"],NewList),
  59.     append(["ZXQbegin"],List5,List4),
  60.     WriteList(List5).
  61.  
  62.   /* Split a string up into individual words by using "FrontToken". */
  63. splitup(S,[H|T]) if fronttoken(S,H,S1),!,splitup(S1,T).
  64. splitup(_,[]).
  65.  
  66.  
  67.   /* This "append" is slightly limited -- append(X,[],X) is true,   */
  68.   /* but append([],X,X) is not.  And append([],[],[]) is also false.*/
  69.   /* The order of the two clauses is important -- when we call on   */
  70.   /* append to generate the possible partitions of a list (i.e.,    */
  71.   /* "append(L,M,[some list])", with L and M not instantiated), we  */ 
  72.   /* want the largest L's to appear FIRST.                */
  73.   
  74. append([X|L1], L2, [X|L3]) if append(L1,L2,L3).
  75. append([X],L,[X|L]) if bound(X).
  76.  
  77.   /* Y is a "conj" of X if the first part of Y is a "change" of the*/
  78.   /* first part of X, and the remainder of Y is a "conj" of the    */
  79.   /* remainder of X.  Note that we don't want ALL the possibilities*/
  80.   /* else we'd get "you are" -> "I am" and then also "you" -> "I". */
  81.   /* Hence the CUT after the first change succeeds.                */
  82. conj([],[]).  
  83. conj(X,Y) :-
  84.     append(Z1,R1,X),
  85.     change(Z1,Z2),!,
  86.     conj(R1,R2),        /*Had to reverse these two lines*/
  87.     append(Z2,R2,Y).    /* (this is the other one)    */
  88.  
  89. WriteList([]).
  90. WriteList([H|T]) :- write(H," "), WriteList(T), nl, fail.
  91.  
  92.   /* Here is the database of CHANGES.  Note the use of the markers  */
  93.   /* "ZXQbegin" and "ZXQend".  The former helps us get the capital- */
  94.   /* ization right, and the latter helps decide whether to change   */
  95.   /* "you" into "I" or "me".                        */
  96.  
  97.     change(["You","are"],["I","am"]).
  98.     change(["you","are"],["I","am"]).
  99.     change(["I","am"],["you","are"]).
  100.     change(["ZXQbegin","I","am"],["ZXQbegin","You","are"]).
  101.     change(["you","'","re"],["I'm"]).
  102.     change(["You","'","re"],["I'm"]).  
  103.     change(["I","'","m"],["you're"]).
  104.     change(["ZXQbegin","I","'","m"],["ZXQbegin","you're"]).  
  105.     change(["you","."],["me","."]).
  106.     change(["you","?"],["me","?"]).  
  107.     change(["you","!"],["me","!"]).
  108.     change(["you","ZXQend"],["me","ZXQend"]).  
  109.     change(["to","you"],["to","me"]).
  110.     change(["for","you"],["for","me"]).
  111.     change(["of","you"],["of","me"]).  
  112.     change(["are","you"],["am","I"]).
  113.     change(["Are","you"],["Am","I"]).
  114.     change(["am","I"],["are","you"]).
  115.     change(["Am","I"],["Are","you"]).
  116.     change(["me"],["you"]).
  117.     change(["you"],["I"]).
  118.     change(["You"],["I"]).
  119.     change(["ZXQbegin","I"],["ZXQbegin","You"]).
  120.     change(["I"],["you"]).
  121.     change(["your"],["my"]).
  122.     change(["my"],["your"]).
  123.     change(["yours"],["mine"]).
  124.     change(["mine"],["yours"]).
  125.     change(["yourself"],["myself"]).
  126.     change(["myself"],["yourself"]).
  127.     change([X],[X]). /* The "catchall" -- X changes to X */
  128.